<?php
/**
 * @file $HeadURL: sns_myprofile.php $
 * @author $Author: LiangJian (liangjian@haibao.com) $
 * @date $Date: 2015-4-2 下午2:12:27 $
 * @brief 
 */
namespace haibao\app\data;

class SnsMyProfile extends \haibao\app\data\BaseMysql{

	public function __construct(){
		parent::__construct('\haibao\app\model\data\SnsMyProfile');
		$this->setConfig( \haibao\classlibrary\app\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_DZ3 );
	}

	public function getProfileByUserId($userId){
		$sql = 'SELECT a.*,b.avatar,b.id as profile_id from auth_user as a left join sns_myprofile as b on a.id=b.user_id WHERE a.id=%s and a.is_active=1';
		$result = $this->query($sql, array(
				$userId
		));
		return $result->fetch_assoc();
	}
	
	public function addSnsProfile($model){
		$this->add($model);
	}
	
	public function getIdByUserId($userId){
	    $sql = 'SELECT id from sns_myprofile where user_id=%s';
	    $result = $this->query($sql, array(
	        $userId
	    ));
	    $retArr = $result->fetch_assoc();
	    return $retArr['id'];
	}

}